//
//  QSSingInInterface.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/28.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSSingInInterface.h"
#import "QSRequestManager.h"

@implementation QSSingInInterface
//是否展示全部企业（获取绑定企业的先提条件）
+ (void)getShowAllCompanyAndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSString *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetShowAllCompany];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode && responseDataDic) {
            NSString *isShowStr = (NSString *) responseDataDic;
            block(rspStatusAndMessage, isShowStr);
        }
    }];
}

+ (void)getCompanyListWithPageIndex:(NSInteger)pageIndex
                       EpAllCompany:(NSString *)epAllCompany
                           andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSBindingEnterprisesModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetSignCompanys];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:epAllCompany forKey:@"epAllCompany"];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode && responseDataDic) {
            QSBindingEnterprisesModel *model = [QSBindingEnterprisesModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}


+ (void)addSignRecorWithEsCompanyKey:(NSString *)esCompanyKey
                            EsAdress:(NSString *)esAdress
                              EsTime:(NSString *)esTime
                            AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kSignInInsert];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:esCompanyKey forKey:@"esCompanyKey"];
    [bodyDic setObject:esAdress forKey:@"esAdress"];
    [bodyDic setObject:esTime forKey:@"esTime"];
    
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

+ (void)insertSignRemarkWithEsid:(NSString *)esId
                    EsRemark:(NSString *)esRemark
                       EsPic:(NSString *)esPic
                    AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kSignRemarkUpdate];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:esId forKey:@"esId"];
    [bodyDic setObject:esRemark forKey:@"esRemark"];
    if (esPic) {
        [bodyDic setObject:esPic forKey:@"esPic"];
    }    
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

+ (void)getSignInfoWithEsId:(NSString *)esid
                     dBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kSignFindByEsId];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:esid forKey:@"esId"];
    
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}


/**
* @brief 获取人员下拉列表
 level 当前等级
*/
+ (void)getApiSignDetailWithLevel:(NSInteger)level
                           dBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kApiSignDetail];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(level) forKey:@"level"];

    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
 * @brief 获取签到记录的签到数量
 * level 当前人员的等级
 * companyKey 如果是服务员，则可以通过切换公司ID切换签到数量
 * epId 组长取epid
 * egid 领导取egid
 */

+ (void)getApiSignNumsWithLevel:(NSInteger)level
                     CompanyKey:(NSString *)companyKey
                           EpId:(NSInteger)epId
                           EgId:(NSInteger)egId
                       andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSSignNumModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kApiSignNums];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (epId) {
        [bodyDic setObject:@(epId) forKey:@"epId"];
    }
    if (egId) {
        [bodyDic setObject:@(egId) forKey:@"egId"];
    }
    [bodyDic setObject:@(level) forKey:@"level"];
    [bodyDic setObject:QSNoNilString(companyKey) forKey:@"companyKey"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSSignNumModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            model = [QSSignNumModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 获取签到记录List
 *flag 默认1 今日签到 2为本月签到 3为上月签到
 *level 前方法得到的级别
 *esRemark 备注
 *epId 组长——如果切换了组员
 *egId 领导——如果切换了组
 *companyKey 服务员——如果切换了公司
*/
+ (void)getSignListWithPageIndex:(NSInteger)pageIndex
                            Flag:(NSInteger)flag
                              Level:(NSInteger)level
                            Epid:(NSInteger)epId
                            Egid:(NSInteger)egId
                      CompanyKey:(NSString *)companyKey
                        AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSSignRecordListModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kApiSignList];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (epId) {
        [bodyDic setObject:@(epId) forKey:@"epId"];
    }
    if (egId) {
        [bodyDic setObject:@(egId) forKey:@"egId"];
    }
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [bodyDic setObject:@(flag) forKey:@"flag"];
    [bodyDic setObject:@(level) forKey:@"level"];
    [bodyDic setObject:QSNoNilString(companyKey) forKey:@"companyKey"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSSignRecordListModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            model = [QSSignRecordListModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

@end
